import os
import time

from data.wencai.core.crawler import Wencai


def wencai_search_ths(query):
    """
    :param query: 查询字符串
    :param exist: false 覆盖文件
    :return:
    """
    # print(query)
    # file = './data/wencai/data/' + query + '.xlsx'
    # if os.path.exists(file) and exist:
    #     result = pd.DataFrame(pd.read_excel(file, converters={'code': str}))
    # else:
    time.sleep(3)  # 频繁刷新会封IP
    wencai = Wencai()
    count = 6
    while count > 0:
        count = count - 1
        result = wencai.search(query)
        if result is not None:
            break
        time.sleep(3)
    if count == 1:
        raise ValueError('问财查询失败')
    return result


if __name__ == '__main__':
    print(wencai_search_ths('去掉ST 20221229涨停 开盘涨幅 20221229实体涨幅'))
